<template>
  <view class="Box">
    <view class="typeBox">
      <view v-for="item in typeList" :key="item.value" class="">
        <view :class="['typeItem',typeIndex == item.value?'typeSelete':'']" @click="typeClick(item.value)">
          {{ item.name }}
        </view>
      </view>
    </view>
    <view class="listBox">
      <view class="listLeft">
        <view v-for="(item,index) in popularSiteOne" :key="index" class="">
          <view class="listItem" @click="shopsClick(item.id,item.type)">
            <view class="imgBox">
              <view v-if="item.type == 1" class="imgType">餐饮</view>
              <view v-if="item.type == 2" class="imgType imgTypeOne">住宿</view>
              <view v-if="item.type == 3" class="imgType imgTypeTwo">零售</view>
              <image :src="item.shopImgList[0]" class="img"></image>
            </view>
            <view class="listName">
              {{ item.shopName }}
            </view>
            <view class="tagBox">
              <view v-for="(params,parIndex) in item.tag" :key="parIndex" class="">
                <view class="tagItem">
                  {{ params }}
                </view>
              </view>
            </view>
            <view class="capita">
              <view class="">
                人均:
              </view>
              <view class="moneyBox">
                <view class="icon">
                  ￥
                </view>
                <view class="money">
                  {{ item.consumptionPerPerson }}
                </view>
              </view>
            </view>
          </view>

        </view>
      </view>
      <view class="listRight">
        <view v-for="(item,index) in popularSiteTwo" :key="index" class="">

          <view class="listItem" @click="shopsClick(item.id,item.type)">
            <view class="imgBox">
              <view v-if="item.type == 1" class="imgType">餐饮</view>
              <view v-if="item.type == 2" class="imgType imgTypeOne">住宿</view>
              <view v-if="item.type == 3" class="imgType imgTypeTwo">零售</view>
              <view v-if="item.type == 4" class="imgType imgTypeThree">平台</view>
              <image :src="item.business" class="img"></image>
            </view>
            <view class="listName">
              {{ item.shopName }}
            </view>
            <view class="tagBox">
              <view v-for="(params,parIndex) in item.tag" :key="parIndex" class="">
                <view class="tagItem">
                  {{ params }}
                </view>
              </view>
            </view>
            <view class="capita">
              <view class="">
                人均:
              </view>
              <view class="moneyBox">
                <view class="icon">
                  ￥
                </view>
                <view class="money">
                  {{ item.consumptionPerPerson }}
                </view>
              </view>
            </view>
          </view>

        </view>
      </view>
    </view>
    <view class="block5">
      <view v-if="(popularSiteOne.length + popularSiteTwo.length) < total" class="">
        <u-loadmore line loadmoreText="点击加载更多" status="loadmore" @loadmore="loadmore"/>
      </view>

      <view v-else class="noMore">
        <tui-nomore backgroundColor="#F2F2F2" text="到底了 "></tui-nomore>
      </view>
    </view>
  </view>
</template>

<script>
import {
  queryShop
} from "@/api/challenge";

export default {
  data() {
    return {
      total: 0,
      typeList: [{
        name: '全部',
        value: 0
      }, {
        name: '餐饮',
        value: 1
      }, {
        name: '住宿',
        value: 2
      }, {
        name: '零售',
        value: 3
      },],
      typeIndex: 0,
      objData: {
        type: '',
        page: 1,
        size: 10
      },
      popularSiteOne: [],
      popularSiteTwo: []
    }
  },
  onLoad() {
    this.queryShopEvent()
  },
  methods: {
    loadmore() {
      this.objData.page += 1
      this.queryShopEvent()
    },
    shopsClick(id, type) {
      console.log(id, type);
      uni.navigateTo({
        url: '/pages/popular_destination/peripheryDetails?id=' + id
      });
    },
    typeClick(data) {
      this.typeIndex = data
      if (data != 0) {
        this.objData.type = data
      } else {
        this.objData.type = ""
      }
      this.objData.page = 1
      this.queryShopEvent()
    },
    queryShopEvent() {
      var data = {}
      for (let key in this.objData) {
        if (this.objData[key] != '') {
          data[key] = this.objData[key]
        }
      }
      queryShop(data).then(res => {
        this.total = res.total
        if (this.objData.page == 1) {
          this.popularSiteOne = []
          this.popularSiteTwo = []
        }

        res.records.forEach(item => {
          if (this.popularSiteOne.length == this.popularSiteTwo.length) {
            var idynamicTags = []
            item.tag.split(",").forEach((item, index) => {
              if (item != '') {
                idynamicTags.push(item)
              }
            })
            item.tag = idynamicTags
            this.popularSiteOne.push(item)
          } else {
            var idynamicTags = []
            item.tag.split(",").forEach((item, index) => {
              if (item != '') {
                idynamicTags.push(item)
              }
            })
            item.tag = idynamicTags
            this.popularSiteTwo.push(item)
          }
        })


      })
    },
  }
}
</script>

<style lang="scss" scoped>
.Box {
  width: 100%;
  height: 100vh;
  background-color: #f2f2f2;
  font-family: PingFang SC, PingFang SC-Regular;
}

.typeBox {
  width: 100%;
  height: 100rpx;
  background-color: #fff;
  display: flex;
  justify-content: space-evenly;

  .typeItem {
    width: 128rpx;
    height: 56rpx;
    line-height: 56rpx;
    background: #eeeeee;
    border: 1px solid #eeeeee;
    border-radius: 8rpx;
    text-align: center;
    margin-top: 22rpx;
    color: #757575;
  }

  .typeSelete {
    background: #e5efff;
    border: 1px solid #4186f5;
    color: #4186f5;
  }
}

.listBox {
  display: flex;
  padding: 32rpx;
  background-color: #f2f2f2;
}

.listLeft {
  margin-right: 32rpx;
}

.listItem {
  width: 326rpx;
  background: #ffffff;
  border-radius: 20rpx;
  box-shadow: 0rpx 4rpx 12rpx 0rpx rgba(0, 0, 0, 0.10);
  margin-bottom: 32rpx;
}

.imgBox {
  width: 100%;
  position: relative;
  border-radius: 20rpx 20rpx 0 0;

  .imgType {
    width: 92rpx;
    height: 40rpx;
    border-radius: 20rpx 0rpx 20rpx 0rpx;
    position: absolute;
    top: 0;
    left: 0;
    background-color: #ff9802;
    text-align: center;
    color: #fff;
    font-size: 24rpx;
    line-height: 40rpx;
    z-index: 10;
  }

  .imgTypeOne {
    background-color: #4186f5;
  }

  .imgTypeTwo {
    background-color: #8abc10;
  }

  .imgTypeThree {
    background-color: #ff0000;
  }

  .img {
    width: 100%;
    height: 310rpx;
    border-radius: 20rpx 20rpx 0 0;
  }


}

.listName {
  font-size: 28rpx;
  font-weight: 800;
  margin-left: 20rpx;
}

.tagBox {
  display: flex;
  flex-wrap: wrap;
  margin: 10rpx 0 20rpx 20rpx;

  .tagItem {
    color: #ff9802;
    padding: 0rpx 8rpx;
    border: 1px solid #ff9802;
    border-radius: 4px;
    margin: 0 10rpx 10rpx 0;
  }
}

.capita {
  border-top: 2rpx solid #e3e3e3;
  display: flex;
  align-items: baseline;
  padding: 20rpx 0 20rpx 20rpx;

  .moneyBox {
    display: flex;
    align-items: baseline;
    color: #ff0000;

    .money {
      font-size: 50rpx;
      font-weight: 800;
    }
  }
}

.block5 {
  width: 100%;
  display: flex;
  /* 使用Flexbox布局 */
  flex-direction: column;
  /* 设置为垂直方向 */
  align-items: center;
  /* 水平居中 */
  justify-content: center;
  /* 垂直居中 */
  height: 400rpx;
  /* 确保有足够的高度，根据需要调整高度 */
  background-color: #F2F2F2;

  .noMore {
    width: 100%;
    text-align: center;
  }
}
</style>
